package com.xuecheng.content.config.rabbitmq;

import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Component
public class RabbitMQConsumer {

    /* 简单形式：只去指定队列名称（此队列必须要提前声明出来）*/
    //@RabbitListener(queues = "test.queue")
    //public void publishPage(String msg) {
    //    System.out.println("收到消息："+msg);
    //}



    /* 绑定交互级和队列形式：推荐使用此方式 */
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(value="test.queue"),
            exchange = @Exchange(value ="test.direct",type = ExchangeTypes.DIRECT),
            key = {"test"}
    ))
    public void publishPage(String msg) {
        System.out.println("收到消息："+msg);
    }

}